package demo21;

import java.util.ArrayList;
import java.util.List;

/**
 * 字母大小写全排列
 * https://leetcode.cn/problems/letter-case-permutation/submissions/568445935/
 */
class Solution {
    List<String> ret = new ArrayList<>();
    char[] path;
    int len;
    public List<String> letterCasePermutation(String s) {
        path = s.toCharArray();
        len = path.length;
        dfs(0);
        return ret;
    }

    private void dfs(int index) {
        while(index < path.length && !Character.isLetter(path[index])) {
            index ++; // 不是字符
        }
        if(index == len) {
            ret.add(new String(path));
            return;
        }
        path[index] ^= 32;
        dfs(index + 1);
        path[index] ^= 32;
        dfs(index + 1);
    }
}
class Demo {
    public static void main(String[] args) {
        Solution solution = new Solution();
        List<String> a1b2 = solution.letterCasePermutation("a1b2");
        System.out.println();
        for(String str : a1b2) {
            System.out.println(str);
        }
    }
}